<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../font/iconfont.css">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            background-image: url(../蔡徐坤.jpg);
            background-size: 100%;
        }

        .ly {
            width: 100px;
            height: 50px;
            margin-top: 30px;
            margin-left: 30px;
        }

        textarea {
            width: 400px;
            height: 100px;
            margin-left: 20px;
        }

        .z {
            width: 450px;
            height: 210px;
            background-color: #fff;
            position: absolute;
            left: 0;
            top: 0;
            bottom: 0;
            right: 0;
            margin: auto;
            display: none;

        }

        .s {
            width: 450px;
            height: 30px;
            background-color: #999;
            align-content: center;
        }

        b {
            margin-left: 200px;
        }

        #span {
            margin-left: 150px;
        }

        .an {
            width: 100px;
            margin-left: 130px;
        }

        .qd,
        .gb {
            width: 100px;
        }

        li {
            width: 800px;
            height: 100px;
            background-color: #fff;
            margin-top: 20px;
            margin-left: 30px;
            list-style: none;
            padding-left: 10px;
            padding-top: 10px;
            overflow: hidden;
        }

        li:hover {
            #sp {
                display: block;
            }
        }

        #sp {
            float: right;
            margin-right: 20px;
            font-size: 20px;
            display: none;
        }
    </style>
</head>

<body>
    <div>
        <button class="ly" onclick="ly()">点击留言</button>
        <div class="z">
            <div class="s">
                <b>massage<span id="span" onclick="gb()" class="iconfont  icon-chahao"></span></b>
            </div>
            name:<input type="text"><br>
            content:
            <textarea></textarea>
            <span class="an">
                <button class="qd" onclick="qd()">确定</button>
                <button class="gb" onclick="gb()">关闭</button>
            </span>
        </div>
        <ul>
        </ul>
    </div>
</body>

</html>
<script>
    var z = document.querySelector('.z')
    var input = document.querySelector('input')
    var text = document.querySelector('textarea')
    var ul = document.querySelector('ul')

    function ly() {
        z.style.display = 'block'
    }
    function gb() {
        z.style.display = 'none'
        input.value = ''
        text.value = ''
    }
    function qd() {
        var date = new Date()
        var year = date.getFullYear()
        var yue = date.getMonth() + 1
        var ri = date.getDate()
        var shi = date.getHours();
        var fen = date.getMinutes()
        var miao = date.getSeconds()
        var li = document.createElement("li")
        var shii = 0
        if (shi > 12) {
            shii = '下午' + (shi - 12)
        } else {
            shii = shi
        }
        if (input.value.trim() == '') {
            alert("name不能为空")
            return
        }
        if (text.value.trim() == '') {
            alert("content不能为空")
            return
        }
        li.innerHTML = `
            <h4>${input.value}</h4>
            <span>${year}/${yue}/${ri} ${shii}:${fen}:${miao}<span id="sp" onclick="sc(this)"  class="iconfont  icon-chahao"></span></span><br><br>
            <span>${text.value}</span>
        `;
        ul.insertBefore(li, ul.children[0])
        input.value = ''
        text.value = ''
        z.style.display = 'none'
    }
    function sc(t) {
        ul.removeChild(t.parentNode.parentNode)
    }
</script>